#!/usr/bin/env bash

set -e -u -x
source ./tasks/helpers.sh

task_working_dir

# Install into the task's special _persist directory so that these dependencies
# for the tasks/app/core task are still present if core needs to be re-run, but
# not this task.
mkdir -p _persist
cd _persist

rsync -a \
  --itemize-changes \
  --delete \
  --delete-excluded \
  --include=/assets/*** \
  --include=/webpack.config.js \
  --exclude=* \
  "$SOURCE_DIR/src/api-umbrella/web-app/" \
  ./

# Symlink the local node_modules to the system-wide node directory.
#
# Note, we create a `.pnpm` directory inside (even if pnpm isn't being used,
# since it won't hurt anything), since it seems to sidestep this issue of
# install failing if node_modules is a symlink:
# https://github.com/pnpm/pnpm/issues/7690
node_modules_dir="$WORK_DIR/tasks/app-deps/web-app/pnpm/_persist/node_modules"
mkdir -p "${node_modules_dir}/.pnpm"
ln -s "$node_modules_dir" ./node_modules
PATH="$DEV_PATH" ./node_modules/.bin/webpack

stamp
